package ro.tm.uvt.lp.raccoon.catchGame.environment;

import com.badlogic.gdx.Gdx;

import java.util.ArrayList;

import ro.tm.uvt.lp.raccoon.catchGame.entities.Entity;
import ro.tm.uvt.lp.raccoon.catchGame.entities.agents.Dog;
import ro.tm.uvt.lp.raccoon.catchGame.entities.agents.Raccoon;
import ro.tm.uvt.lp.raccoon.catchGame.entities.physicalObjects.Burrow;
import ro.tm.uvt.lp.raccoon.catchGame.entities.physicalObjects.Food;
import ro.tm.uvt.lp.raccoon.catchGame.entities.physicalObjects.NatureStaticEntity;

/**
 * Created by user on 1/14/2015.
 */
public class Cell {

    //can be nature stuff used for checking if agents collide
    //or it could be food and then the raccoon can eat that
    private ArrayList<Entity> content =new ArrayList<Entity>();
    private int row,column;
    private int x, y;
    private String type;

    public Cell(){

    }

    public Cell(Entity po){
        this.content.add(po);
        this.x=(int)po.getX();
        this.y=(int)po.getY();
        this.row=y/Environment.INSTANCE.getTileHeight();
        this.column=x/Environment.INSTANCE.getTileWidth();
        if(po instanceof NatureStaticEntity){
            this.type=CellType.NATURE_ITEM;
        }else if(po instanceof Food){
            this.type=CellType.FOOD;
        }else if(po instanceof Raccoon){
            this.type=CellType.RACCOON;
        }else if(po instanceof Dog){
            this.type=CellType.DOG;
        }else if(po instanceof Burrow){
            this.type=CellType.BURROW;
        }
    }

    public Cell(int row, int column){
        this.row=row;
        this.column=column;
        this.x=column*Environment.INSTANCE.getTileWidth();
        this.y=row*Environment.INSTANCE.getTileHeight();
    }

    public ArrayList<Entity> getContent() {
        return content;
    }

    public void setContent(ArrayList<Entity> content) {
        this.content = content;
    }

    public void addEntity(Entity entity){
        this.content.add(entity);
    }

    public boolean deleteEntity(Entity entity){
        return this.content.remove(entity);
    }

    public int getRow() {
        return row;
    }

//    public void setRow(int row) {
//        this.row = row;
//    }

    public int getColumn() {
        return column;
    }

//    public void setColumn(int column) {
//        this.column = column;
//    }

    public int getX() {
        return x;
    }

    public void setX(int x) {
        this.x = x;
        this.row=x/Environment.INSTANCE.getTileWidth();
    }

    public int getY() {
        return y;
    }

    public void setY(int y) {
        this.y = y;
        this.column=y/Environment.INSTANCE.getTileHeight();
    }


    public boolean isOcupied(int row, int column){

//        Gdx.app.debug(">>>>>>>>>>>>>>Cell.isOcupied: ",this.row+" "+this.column+" "+this.content.size()+" :: "+row+" "+column);

        if(this.row==row && this.column==column)
            return true;
        return false;
    }

    public String getType(){
        return this.type;
    }

    public String toString(){
        return type+": "+row+" "+column+" >>>  "+x+" "+y;
    }
}
